const express = require("express")

// 导入效验规则的中间件
const { createValidator } = require('express-joi-validation');


const app = express();
app.use(express.json());
const validator = createValidator({});
const router = express()
// 引入规则
const { registerSchema,loginSchema,userInfoSchema,wxLoginSchema,userRolesSchema, updateInfoSchema  } = require("../rule/auth.js")
// 引入处理函数
const { useLogin,useRegister,getUserInfo,wxLogin, updateUserInfo,getUserlist,userRolesSheel, getUserRoles } = require("../views/auth.js") 
// pc 或者 app
router.post("/users/login",validator.body(loginSchema),useLogin)
router.post("/register",validator.body(registerSchema),useRegister)
router.get("/users/info", validator.query(userInfoSchema),getUserInfo)
router.get("/users/list",getUserlist)

router.post('/users/roles',validator.body(userRolesSchema),getUserRoles)
router.get("/roles/list",userRolesSheel)

router.post("/update/userInfo" ,validator.body(updateInfoSchema),updateUserInfo)

// 小程序
router.post("/wxLogin",validator.body(wxLoginSchema),wxLogin)





module.exports = router

